package com.youhome.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.youhome.mapper.CounselorRecommendHouseMapper;
import com.youhome.model.CounselorRecommendHouse;
import com.youhome.service.CounselorRecommendHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * Created by chen365 on 2018/09/17.
 */
@Service
public class CounselorRecommendHouseServiceImpl implements CounselorRecommendHouseService {
    @Autowired
    private CounselorRecommendHouseMapper counselorRecommendHouseMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return counselorRecommendHouseMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteByBean(CounselorRecommendHouse record) {
        return counselorRecommendHouseMapper.deleteByBean(record);
    }

    @Override
    public int insert(CounselorRecommendHouse record) {
        record.setCreateTime(new Date());
        return counselorRecommendHouseMapper.insert(record);
    }

    @Override
    public int insertSelective(CounselorRecommendHouse record) {
        record.setCreateTime(new Date());
        return counselorRecommendHouseMapper.insertSelective(record);
    }

    @Override
    public CounselorRecommendHouse selectByPrimaryKey(Long id) {
        return counselorRecommendHouseMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<CounselorRecommendHouse> selectByBean(Integer pageNumber, Integer pageSize, CounselorRecommendHouse record) {
        if (StringUtils.isEmpty(pageNumber) || pageNumber < 1) {
            pageNumber = 1;
        }
        if (StringUtils.isEmpty(pageSize) || pageSize < 10) {
            pageSize = 10;
        }
        PageHelper.startPage(pageNumber, pageSize);
        List<CounselorRecommendHouse> counselorRecommendHouses = counselorRecommendHouseMapper.selectByBean(record);

        return new PageInfo<>(counselorRecommendHouses);
    }

    @Override
    public int updateByPrimaryKeySelective(CounselorRecommendHouse record) {
        record.setUpdateTime(new Date());
        return counselorRecommendHouseMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(CounselorRecommendHouse record) {
        record.setUpdateTime(new Date());
        return counselorRecommendHouseMapper.updateByPrimaryKey(record);
    }

    @Override
    public boolean selectExistsByBean(CounselorRecommendHouse record) {
        if (counselorRecommendHouseMapper.selectExistsByBean(record) > 0) {
            return true;
        }
        return false;
    }
}
